package com.salary.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.salary.dao.SalariesMapper;
import com.salary.dao.WorkMapper;
import com.salary.entity.Salaries;
import com.salary.entity.Work;
import com.salary.entity.view.SalariesView;
import com.salary.entity.view.WorkView;
import com.salary.qpage.QPage;
import com.salary.service.ISalariesService;
import com.salary.service.IWorkService;
import com.salary.util.Result;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 员工考勤业务接口实现层
 */
@Service
public class WorkServiceImpl extends ServiceImpl<WorkMapper, Work> implements IWorkService {


    /**
     * 列表分页
     * @param qPage
     * @param obj
     * @return
     */
    @Override
    public IPage getList(QPage qPage, WorkView obj) {
        IPage iPage = new Page(qPage.getOffset(), qPage.getLimit());
        List<WorkView> mapList = baseMapper.list(iPage,obj);
        return iPage.setRecords(mapList);
    }

    /**
     * 新增
     * @param obj
     * @return
     */
    @Override
    public Result insert(Work obj) {
        obj.setCtime(new Date());
        this.baseMapper.insert(obj);
        return Result.reOk("新增成功");
    }

    /**
     * 修改
     * @param obj
     * @return
     */
    @Override
    public Result updates(Work obj) {
        int isOk=this.baseMapper.updateById(obj);
        if(isOk==1){
            return Result.reOk("修改成功");
        }
        return Result.reError("修改失败");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public Result deleteId(Integer id) {
        int isOk=this.baseMapper.deleteById(id);
        if(isOk==1){
            return Result.reOk("删除成功");
        }
        return Result.reError("删除失败");
    }



}
